#include <tcr.cc>

Point random_point()
{
	return mk_point(rand() % 200 - 100, rand() % 200 - 100, 1);
}

int main()
{
	for(int ii = 0; ii < 1000; ii++)
	{
		Point a = random_point();
		Point b = random_point();
		Point c = random_point();

		Line la = cross(b, c);
		Line lb = cross(c, a);
		Line lc = cross(a, b);

		if(full_dot(a, cross(b, c)) == 0)
		{
			ii--;
			continue;
		}
		
		Point i = incentre(a, b, c);

		Rational p = dist2_pt_line(i, la);
		Rational q = dist2_pt_line(i, lb);
		Rational r = dist2_pt_line(i, lc);

      double pd = sqrt(p.x / p.z);
      double qd = sqrt(q.x / q.z);
      double rd = sqrt(r.x / r.z);

		if(fabs(pd - qd) >= 10000.0 * EPSILON || fabs(qd - rd) >= 10000.0 * EPSILON)
			printf("FAILED %d:\n\tA: %f %f %f\n\tB: %f %f %f\n\tC: %f %f %f\n\tI: %f %f %f\n\tP, Q, R: %f %f %f\n", ii+1, a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, i.x, i.y, i.z, p.x/p.z, q.x/q.z, r.x/r.z);
		else
			printf("PASSED %d\n", ii+1);
	}
}
